package com.rem.designPattern.prototype原型.improve;

/**
 * 原型模式
 * 用原型实例指定创建对象的种类，并且通过复制这些原型创建新的对象
 * 浅拷贝-基本类型和String 值拷贝，引用类型拷贝引用地址
 *
 * @author Rem
 * @date 2022-11-15
 */
public class Client {

    public static void main(String[] args) {
        System.out.println("原型模式完成对象的创建");
        Sheep friend = new Sheep("jack", 2);
        Sheep sheep = new Sheep("tom", 1, friend);

        Sheep sheep2 = sheep.clone();
        Sheep sheep3 = sheep.clone();

        System.out.println("sheep =" + sheep + " sheep1.friend=" + sheep.getFriend().hashCode());
        System.out.println("sheep2 =" + sheep2 + " sheep2.friend=" + sheep2.getFriend().hashCode());
        System.out.println("sheep3 =" + sheep3 + " sheep3.friend=" + sheep3.getFriend().hashCode());
    }
}
